# -*- coding: utf-8 -*-
kimonolabs.com, login and get your own credentialsapi.name <- '1xl232p8'
api.key <- 'DTndIua4tfpz5kxITOILI6FvmGV8xw9g'
install.packages("RCurl", "rjson")
library(RCurl)
library(rjson)
json.url <- paste0('https://www.kimonolabs.com/api/', api.name, '?apikey=', api.key)
json.url
[1] "https://www.kimonolabs.com/api/1xl232p8?apikey=DTndIua4tfpz5kxITOILI6FvmGV8xw9g"
json.file <- getURL(json.url, .encoding = 'UTF-8')
json.data <- fromJSON(json.file)
$name
[1] "RIA Lenta"
$count
[1] 20
$frequency
[1] "Every 15 mins"
$version
[1] 81
$newdata
[1] FALSE
$lastrunstatus
[1] "success"
$thisversionrun
[1] "Fri Oct 30 2014 06:10:49 GMT+0000 (UTC)"
$lastsuccess
[1] "Fri Oct 30 2014 06:25:59 GMT+0000 (UTC)"
$nextrun
[1] "Fri Oct 30 2014 06:40:59 GMT+0000 (UTC)"
$results
# seconds since epoch
as.POSIXct()
# list of parameters
as.POSIXlt()
# Date only
as.Date()
# Convert strings to datetime
strptime(x, format)
# get element from POSIXlt
# sec, min, hour, mday, mon, years, wday, yday
# Specify format
strftime(x, format)
# formats:
# %Y, %m, %d, %b, %H, %M, %S...
# tiemdelta: in seconds:
Sys.time() - 3600
s <- 'This is my test string'
substr(s, 6, 7)
[1] "is"
strsplit(s, ' ')
[[1]]
[1] "This" "is" "my" "test" "string"
tolower(s)
[1] "this is my test string"
Simple usage:
grep(pattern, x)
Complicated:
grep(pattern, x, ignore.case = FALSE, value = FALSE,
fixed = FALSE, invert = FALSE)
head(airquality)
Ozone Solar.R Wind Temp Month Day
1 41 190 7.4 67 5 1
2 36 118 8.0 72 5 2
3 12 149 12.6 74 5 3
4 18 313 11.5 62 5 4
5 NA NA 14.3 56 5 5
6 28 NA 14.9 66 5 6
library(reshape2)
long <- melt(airquality, id.vars=c('Month', 'Day'))
head(long)
Month Day variable value
1 5 1 Ozone 41
2 5 2 Ozone 36
3 5 3 Ozone 12
4 5 4 Ozone 18
5 5 5 Ozone NA
6 5 6 Ozone 28
wide <- dcast(long, Month + Day ~ variable)
head(wide)
Month Day Ozone Solar.R Wind Temp
1 5 1 41 190 7.4 67
2 5 2 36 118 8.0 72
3 5 3 12 149 12.6 74
4 5 4 18 313 11.5 62
5 5 5 NA NA 14.3 56
6 5 6 28 NA 14.9 66
library(ggplot2)
qplot(Sepal.Length, data=iris, geom="histogram")
qplot(factor(Species), Sepal.Length, data=iris, geom="violin")
library(RColorBrewer)
display.brewer.all()